package cn.aopmin.pojo;

import java.io.Serializable;

/**
 * 用户实体
 * @author aopmin
 */
public class User implements Serializable {
  private Integer id;
  private String username;
  private String password;
  private String email;

  public User() {
  }
  public User(UserBuilder builder){
    this.id = builder.id;
    this.username = builder.username;
    this.password = builder.password;
    this.email = builder.email;
  }


  public static UserBuilder builder() {
    return new UserBuilder();
  }

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  @Override
  public String toString() {
    return "{" +
      "id=" + id +
      ", username='" + username + '\'' +
      ", password='" + password + '\'' +
      ", email='" + email + '\'' +
      '}';
  }

  // 静态内部类
  private static class UserBuilder {
    private Integer id;
    private String username;
    private String password;
    private String email;

    public UserBuilder id(Integer id) {
      this.id = id;
      return this;
    }

    public UserBuilder username(String username) {
      this.username = username;
      return this;
    }

    public UserBuilder password(String password) {
      this.password = password;
      return this;
    }

    public UserBuilder email(String email) {
      this.email = email;
      return this;
    }

 public User build() {
      return new User(this);
    }
  }
  public static void main(String[] args) {
    User user = User.builder().id(1).username("aopmin").password("123456").email("aopmin@163.com").build();
    System.out.println(user);
  }
}
